import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            chat_id: this.$router.params.chat_id,
            comment_id: this.$router.params.comment_id,
            placeholder: '评论',
            replied_id: '',
            content: '',
            comment: [],
            commentss: {
                offset: 0,
                length: 25,
                items: []
            },
        };
        return this.state;
    },
    getComment() {
        var me = this;
        var data = {chat_id: me.state.chat_id, comment_id: me.state.comment_id};
        app.get("web/dynamic_topic/dynamicCommentsGet", data, function(res) {
            me.setState({comment: res.data.result});
        });
    
    },
    listComments() {
        var me = this;
        var data = {
            offset: me.state.commentss.offset, 
            length: me.state.commentss.length,
            chat_id: me.state.chat_id,
            comment_id: me.state.comment_id
        };
        app.get("web/dynamic_topic/dynamicCommentList", data, function(res) {
            var data = [];
            var commentss = me.state.commentss;
            var list = res.data.result.list;
            commentss.items = commentss.items.concat(list);
            me.setState({
                total: res.data.result.total,
                commentss: commentss
            }); 
        });
    },
    listCommentss() {
        var me = this;
        var data = {
            offset: 0, 
            length: 25,
            chat_id: me.state.chat_id,
            comment_id: me.state.comment_id
        };
        app.get("web/dynamic_topic/dynamicCommentList", data, function(res) {
            var data = [];
            var commentss = me.state.commentss;
            var list = res.data.result.list;
            commentss.items = list;
            me.setState({
                total: res.data.result.total,
                commentss: commentss
            }); 
        });
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(content) {
        this.setState({
            content: content
        });
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {},
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
